﻿using System;
using System.Web.Mvc;
using NUnit.Framework;
using WeBlog.Controllers;
using WeBlog.DataContext;
using WeBlog.Interfaces;
using WeBlog.Models;
using WeBlog.Repositories;
using WeBlog.Services;
using WeBlog.Tests.Helpers;
using WeBlog.Tests.Mocks;
using System.Collections.Generic;

namespace WeBlog.Tests.Controllers
{
    [TestFixture]
    public class AccountControllerTests
    {
        private IUnitOfWork _unitOfWork;
        private IEmailService _emailService;
        private User _admin = new User { UserId = 100, Email = "admin@weblog.com", FirstName = "admin", LastName = "admin", Password="admin", Activated = true, RoleFlag=RoleValues.Admin };
        private User _guest = new User { UserId = 200, Email = "guest@weblog.com", FirstName = "guest", LastName = "guest", Password="guest", Activated = true };
        private MockPrincipal _adminPrincipal = new MockPrincipal(new MockIdentity("admin@weblog.com"), new[] { Role.Admin });
        private MockPrincipal _guestPrincipal = new MockPrincipal(new MockIdentity("guest@weblog.com"), new[] { Role.Subscriber });

        [SetUp]
        public void Setup()
        {
            _unitOfWork = new InMemoryUnitOfWork();
            var userRepository = new UserRepository(_unitOfWork);
            _emailService = new FakeEmailService();            
            userRepository.Add(_admin);
            userRepository.Add(_guest);
        }

        [Test]
        public void Activate_Action_Should_Succeed_When_Input_Valid()
        {
            //Arrange
            var repository = new UserRepository(_unitOfWork);
            var user = new User { UserId = 300, Email = "newuser@weblog.com", FirstName = "New", LastName = "User", Activated = false };
            repository.Add(user);
            var controller = new AccountController(_unitOfWork, _emailService);

            //Act
            var result = controller.Activate(300) as RedirectToRouteResult;

            //Assert
            var testUser = repository.Find(300);
            Assert.IsNotNull(result);
            Assert.AreEqual("Default", result.RouteName);
            Assert.IsTrue(testUser.Activated);
        }

        [Test]
        public void Activate_Action_Should_Return_NotFound_For_Invalid_User()
        {
            //Arrange            
            var controller = new AccountController(_unitOfWork, _emailService);

            //Act
            var result = controller.Activate(1) as ViewResult;

            //Assert
            Assert.AreEqual("NotFound", result.ViewName);
        }

        [Test]
        public void Create_Action_Returns_Correct_Model()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);

            //Act
            var result = controller.Create() as ViewResult;

            //Assert
            Assert.IsInstanceOf(typeof(CreateUserFormViewModel), result.ViewData.Model);            
        }

        [Test]
        public void Create_Action_Should_Insert_Account_When_Data_Is_Valid()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            var model = new CreateUserFormViewModel()
            {                
                Email = "newuser@weblog.com",
                FirstName = "New",
                LastName = "User"               
            };

            //Act
            controller.Create(model);

            //Assert
            var repository = new UserRepository(_unitOfWork);
            var user = repository.FindByEmail("newuser@weblog.com");
            Assert.IsNotNull(user);
            Assert.IsFalse(user.Activated);
            Assert.IsTrue(user.IsInRole(Role.Subscriber));
        }

        [Test]
        public void Create_Action_Should_Fail_When_Email_Already_Exists()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            var model = new CreateUserFormViewModel()
            {
                Email = "admin@weblog.com",
                FirstName = "New",
                LastName = "User"
            };

            //Act
            var result = controller.Create(model) as ViewResult;

            //Assert
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }

        [Test]
        public void Delete_Action_Should_Remove_Record()
        {
            //Arrange
            var repository = new UserRepository(_unitOfWork);
            var user = new User { UserId = 400, Email = "newuser@weblog.com", FirstName = "New", LastName = "User", Activated = true };
            repository.Add(user);
            var controller = new AccountController(_unitOfWork, _emailService);

            //Act
            var result = controller.Delete(400) as JsonResult;

            //Assert
            Assert.IsNull(repository.Find(400));
            Assert.IsTrue(((dynamic)result.Data).Success);
        }

        [Test]
        public void Edit_Action_Returns_Correct_Model()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);

            //Act
            var result = controller.Edit(_admin.UserId) as ViewResult;

            //Assert
            Assert.IsInstanceOf(typeof(EditUserFormViewModel), result.ViewData.Model);
            Assert.AreEqual(_admin.Email, ((EditUserFormViewModel)result.ViewData.Model).Email);
        }

        [Test]
        public void Edit_Action_Throws_NotFoundException_For_Invalid_User()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);            

            //Act

            //Assert
            Assert.Throws(typeof(NotFoundException), () => controller.Edit(2));
        }

        [Test]
        public void Edit_Action_Should_Redirect_To_MyAccount_For_Current_User()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = _admin;
            controller.SetFakeControllerContext(_adminPrincipal,_admin);

            //Act
            var result = controller.Edit(100) as RedirectToRouteResult;

            //Assert
            Assert.AreEqual("MyAccount", result.RouteValues["action"]);
        }

        [Test]
        public void Edit_Action_Should_Update_Record_When_Input_Is_Valid()
        {
            //Arrange
            var repository = new UserRepository(_unitOfWork);
            var user = new User { UserId = 500, Email = "newuser@weblog.com", FirstName = "New", LastName = "User", Activated = true };
            var principal = new MockPrincipal(new MockIdentity("guest@weblog.com"), new[] { Role.Subscriber });
            repository.Add(user);

            var formValues = new Dictionary<string, string>();
            formValues.Add("FirstName", "John");
            formValues.Add("LastName", "Doe");
            formValues.Add("Email", "johndoe@weblog.com");
            formValues.Add("RoleFlag", "16");
           
            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = user;
            controller.SetFakeControllerContext(principal, user);
            controller.ValueProvider = MvcMockHelpers.SetupValueProvider(formValues);

            //Act
            controller.Edit(500, new FormCollection());

            //Assert
            var testUser = repository.Find(500);
            Assert.AreEqual("John", user.FirstName);
            Assert.AreEqual("Doe", user.LastName);
            Assert.AreEqual("johndoe@weblog.com", user.Email);
        }

        [Test]
        public void Edit_Action_Should_Fail_When_Input_Is_Invalid()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = _guest;
            controller.SetFakeControllerContext(_guestPrincipal, _guest);

            //Act
            var formValues = new Dictionary<string, string>();
            formValues.Add("FirstName", "John");
            formValues.Add("LastName", "Doe");
            formValues.Add("Email", "johndoe@");
            formValues.Add("RoleFlag", "16");
            controller.ValueProvider = MvcMockHelpers.SetupValueProvider(formValues);
            var result = controller.Edit(200, new FormCollection()) as ViewResult;

            //Assert            
            var repository = new UserRepository(_unitOfWork);
            var user = repository.Find(200);
            Assert.AreEqual("guest", user.FirstName);
            Assert.AreEqual("guest", user.LastName);
            Assert.AreEqual("guest@weblog.com", user.Email);
            Assert.IsInstanceOf(typeof(EditUserFormViewModel), result.ViewData.Model);
        }

        [Test]
        public void Manage_Action_Should_Return_Valid_Model()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);

            //Act
            var result = controller.Manage(new GridSettings("LastName")) as ViewResult;
            
            //Assert            
            Assert.IsInstanceOf(typeof(ManageAccountsViewModel), result.Model);
        }

        [Test]
        public void Register_Action_Should_Return_Valid_View_When_AllowOpenRegistration_Is_True()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
           SiteManager.CurrentConfiguration.AllowOpenRegistration = true;

            //Act
            var result = controller.Register() as ViewResult;

            //Assert            
            Assert.AreEqual("Register", result.ViewName);
        }

        [Test]
        public void Register_Action_Should_Return_NotFound_When_AllowOpenRegistration_Is_False()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
			SiteManager.CurrentConfiguration.AllowOpenRegistration = false;

            //Act
            var result = controller.Register() as ViewResult;

            //Assert            
            Assert.AreEqual("NotFound", result.ViewName);
        }

        [Test]
        public void Register_Action_Should_Return_NotFound_When_AllowOpenRegistration_Is_False2()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
			SiteManager.CurrentConfiguration.AllowOpenRegistration = false;
            var model = new RegisterModel
            {
                ConfirmPassword = "123456",
                Password = "123456",
                Email = "newuser@weblog.com",
                FirstName = "New",
                LastName = "User"
            };

            //Act
            var result = controller.Register(model) as ViewResult;

            //Assert            
            Assert.AreEqual("NotFound", result.ViewName);
        }

        [Test]
        public void Register_Action_Inserts_Proper_Data_For_Valid_Request()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);            
            var model = new RegisterModel
                            {
                                ConfirmPassword = "123456",
                                Password = "123456",
                                Email = "newuser@weblog.com",
                                FirstName = "New",
                                LastName = "User"
                            };

            //Act
            controller.Register(model);

            //Assert     
            var repository = new UserRepository(_unitOfWork);
            var updated = repository.FindByEmail("newuser@weblog.com");
            Assert.IsNotNull(updated);
            Assert.IsFalse(updated.Activated);
            Assert.IsTrue(updated.IsInRole(Role.Subscriber));
        }

        [Test]
        public void Register_Action_Fails_With_Invalid_User_Input()
        {            
            //Arrange
            var repository = new UserRepository(_unitOfWork);
			SiteManager.CurrentConfiguration.AllowOpenRegistration = true;
            var user = new User {Activated = false, Email = "newuser@weblog.com", FirstName = "New", LastName = "User"};
            repository.Add(user);
            var controller = new AccountController(_unitOfWork, _emailService);
            var model = new RegisterModel
                            {
                                ConfirmPassword = "123456",
                                Password = "098765",
                                Email = "newuser@weblog.com",
                                FirstName = "New",
                                LastName = "User"
                            };
            //Act
            var result = controller.Register(model) as ViewResult;

            //Assert
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }

        [Test]
        public void Register_Action_Should_Have_Model_Errors_When_Password_Less_Than_MinPasswordLength()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
			SiteManager.CurrentConfiguration.AllowOpenRegistration = true;
            var model = new RegisterModel
            {
                ConfirmPassword = "1",
                Password = "1",
                Email = "newuser@weblog.com",
                FirstName = "New",
                LastName = "User"
            };

            //Act
            var result = controller.Register(model) as ViewResult;

            //Assert
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }

        [Test]
        public void MyAccount_Returns_Proper_Model()
        {
            //Arrange            
            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = _admin;
            controller.SetFakeControllerContext(_adminPrincipal,_admin);

            //Act
            var result = controller.MyAccount() as ViewResult;

            //Assert
            Assert.IsInstanceOf(typeof(MyAccountFormViewModel), result.ViewData.Model);
            Assert.AreEqual(((MyAccountFormViewModel)result.ViewData.Model).Email, _admin.Email);
        }

        [Test]
        public void MyAccount_Action_Should_Update_Data_When_Input_Is_Valid()
        {
            //Arrange
            var repository = new UserRepository(_unitOfWork);
            var user = new User { UserId=600, Activated = false, Email = "newuser@weblog.com", FirstName = "New", LastName = "User", Password="1234567" };
            var principal = new MockPrincipal(new MockIdentity("newuser@weblog.com"), new[] { Role.Subscriber });
            repository.Add(user);

            var formValues = new Dictionary<string, string>();
            formValues.Add("OldPassword", "1234567");
            formValues.Add("NewPassword", "0987654321");
            formValues.Add("ConfirmNewPassword", "0987654321");
            formValues.Add("FirstName", "John");
            formValues.Add("LastName", "Doe");
            formValues.Add("Email", "johndoe@weblog.com");
            formValues.Add("RoleFlag", "16");

            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = user;
            controller.SetFakeControllerContext(principal, user);
            controller.ValueProvider = MvcMockHelpers.SetupValueProvider(formValues);

            //Act
            controller.MyAccount(new FormCollection());

            //Assert
            var testUser = repository.Find(600);
            Assert.AreEqual("John", testUser.FirstName);
            Assert.AreEqual("Doe", testUser.LastName);
            Assert.AreEqual("johndoe@weblog.com", testUser.Email);
        }

        [Test]
        public void MyAccount_Action_Should_Fail_When_Input_Is_Invalid()
        {
            //Arrange
            var repository = new UserRepository(_unitOfWork);
            var formValues = new Dictionary<string, string>();
            formValues.Add("FirstName", "John");
            formValues.Add("LastName", "Doe");
            formValues.Add("Email", "johndoe@");
            formValues.Add("RoleFlag", "16");

            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = _guest;
            controller.SetFakeControllerContext(_guestPrincipal, _guest);
            controller.ValueProvider = MvcMockHelpers.SetupValueProvider(formValues);
            
            //Act
            var result = controller.MyAccount(new FormCollection()) as ViewResult;

            //Assert           
            var user = repository.Find(200);
            Assert.AreEqual("guest", user.FirstName);
            Assert.AreEqual("guest", user.LastName);
            Assert.AreEqual("guest@weblog.com", user.Email);
            Assert.IsInstanceOf(typeof(MyAccountFormViewModel), result.ViewData.Model);
        }

        [Test]
        public void MyAccount_Action_Should_Have_Model_Errors_When_Email_Already_Exists()
        {
            //Arrange
            var repository = new UserRepository(_unitOfWork);
            var user = new User { UserId = 700, Activated = false, Email = "newuser@weblog.com", FirstName = "New", LastName = "User" };
            var principal = new MockPrincipal(new MockIdentity("newuser@weblog.com"), new[] { Role.Subscriber });
            repository.Add(user);

            var formValues = new Dictionary<string, string>();
            formValues.Add("FirstName", "newuser");
            formValues.Add("LastName", "newuser");
            formValues.Add("Email", "admin@weblog.com");
            formValues.Add("RoleFlag", "16");

            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = user;
            controller.SetFakeControllerContext(principal, user);
            controller.ValueProvider = MvcMockHelpers.SetupValueProvider(formValues);

            //Act
            var result = controller.MyAccount(new FormCollection()) as ViewResult;

            //Assert
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }

        [Test]
        public void MyAccount_Action_Should_Fail_When_Old_Password_Is_Invalid()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = _guest;
            controller.SetFakeControllerContext(_guestPrincipal, _guest);

            var formValues = new Dictionary<string, string>();
            formValues.Add("OldPassword", "123456");
            formValues.Add("NewPassword", "0987654321");
            formValues.Add("ConfirmNewPassword", "0987654321");
            formValues.Add("FirstName", "guest");
            formValues.Add("LastName", "guest");
            formValues.Add("Email", "guest@weblog.com");
            formValues.Add("RoleFlag", "16");
            controller.ValueProvider = MvcMockHelpers.SetupValueProvider(formValues);

            //Act
            var result = controller.MyAccount(new FormCollection()) as ViewResult;

            //Assert
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }

        [Test]
        public void MyAccount_Action_Should_Fail_When_NewPassword_And_ConfirmPassword_Does_Not_Match()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = _guest;
            controller.SetFakeControllerContext(_guestPrincipal, _guest);

            var formValues = new Dictionary<string, string>();
            formValues.Add("OldPassword", "guest");
            formValues.Add("NewPassword", "1234567");
            formValues.Add("ConfirmNewPassword", "09876543");
            formValues.Add("FirstName", "guest");
            formValues.Add("LastName", "guest");
            formValues.Add("Email", "guest@weblog.com");
            formValues.Add("RoleFlag", "16");
            controller.ValueProvider = MvcMockHelpers.SetupValueProvider(formValues);

            //Act
            var result = controller.MyAccount(new FormCollection()) as ViewResult;

            //Assert
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }

        [Test]
        public void MyAccount_Action_Should_Fail_When_NewPassword_Is_Less_Than_MinPasswordLength()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = _guest;
            controller.SetFakeControllerContext(_guestPrincipal, _guest);

            var formValues = new Dictionary<string, string>();
            formValues.Add("OldPassword", "guest");
            formValues.Add("NewPassword", "1");
            formValues.Add("ConfirmNewPassword", "1");
            formValues.Add("FirstName", "guest");
            formValues.Add("LastName", "guest");
            formValues.Add("Email", "guest@weblog.com");
            formValues.Add("RoleFlag", "16");
            controller.ValueProvider = MvcMockHelpers.SetupValueProvider(formValues);

            //Act
            var result = controller.MyAccount(new FormCollection()) as ViewResult;

            //Assert
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }

        [Test]
        public void Profile_Action_Returns_Proper_Model()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);

            //Act
            var result = controller.Profile(200) as ViewResult;

            //Assert            
            Assert.IsInstanceOf(typeof(UserProfileModel), result.Model);
        }

        [Test]
        public void ResetPassword_Action_Returns_Proper_View()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);

            //Act
            var result = controller.ResetPassword() as ViewResult;

            //Assert            
            Assert.IsNullOrEmpty(result.ViewName);
        }

        [Test]
        public void ResetPassword_Action_Should_Succeed_If_Email_Is_Valid()
        {
            //Arrange
            var repository = new UserRepository(_unitOfWork);
            var user = new User { UserId = 800, Activated = false, Email = "newuser1@weblog.com", FirstName = "New", LastName = "User", Password="newuser" };
            var principal = new MockPrincipal(new MockIdentity("newuser1@weblog.com"), new[] { Role.Subscriber });
            repository.Add(user);          

            var passwordHashBefore = repository.FindByEmail("newuser1@weblog.com").PasswordHash;
            var controller = new AccountController(_unitOfWork, _emailService);
            controller.SetFakeControllerContext(principal, user);            

            //Act
            var result = controller.ResetPassword("newuser1@weblog.com");

            //Assert
            var testUser = repository.FindByEmail("newuser1@weblog.com");
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
            Assert.AreNotEqual(passwordHashBefore, user.PasswordHash);
        }

        [Test]
        public void ResetPassword_Action_Should_Fail_If_Email_Is_Not_Valid()
        {
            //Arrange
            var userRepository = new UserRepository(_unitOfWork);
            var passwordHashBefore = userRepository.FindByEmail("guest@weblog.com").PasswordHash;
            var controller = new AccountController(_unitOfWork, _emailService);
            controller.SetFakeControllerContext(_guestPrincipal, _guest);  

            //Act
            var result = controller.ResetPassword("johndoe@weblog.com") as ViewResult;

            //Assert
            var user = userRepository.FindByEmail("guest@weblog.com");
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
            Assert.AreEqual(passwordHashBefore, user.PasswordHash);
        }

        [Test]
        public void SignIn_Action_Returns_Valid_View()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);

            //Act
            var result = controller.SignIn() as ViewResult;

            //Assert            
            Assert.IsNullOrEmpty(result.ViewName);
        }

        [Test]
        public void SignIn_Action_Should_Succeed_When_Input_Is_Valid()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            var model = new LogOnModel() {Email = "guest@weblog.com", Password = "guest", RememberMe = true};

            //Act
            var result = controller.SignIn(model) as RedirectToRouteResult;

            //Assert
            Assert.AreEqual("guest@weblog.com", System.Threading.Thread.CurrentPrincipal.Identity.Name);
            Assert.IsTrue(System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated);
            Assert.AreEqual("Default", result.RouteName);
        }

        [Test]
        public void SignIn_Action_Should_Fail_When_Password_Is_Invalid()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            var model = new LogOnModel() { Email = "guest@weblog.com", Password = "guest123", RememberMe = true };

            //Act
            var result = controller.SignIn(model) as ViewResult;

            //Assert
            Assert.IsFalse(System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated);
            Assert.IsInstanceOf(typeof(LogOnModel), result.ViewData.Model);
            Assert.AreEqual(((LogOnModel)result.ViewData.Model).Email, _guest.Email);
        }

        [Test]
        public void SignIn_Action_Should_Fail_When_Username_Is_Invalid()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            var model = new LogOnModel() { Email = "guest123@weblog.com", Password = "guest", RememberMe = true };

            //Act
            var result = controller.SignIn(model) as ViewResult;

            //Assert
            Assert.IsFalse(System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated);
            Assert.IsInstanceOf(typeof(LogOnModel), result.ViewData.Model);
        }

        [Test]
        public void SignIn_Action_Should_Fail_When_User_Is_Not_Activated()
        {
            //Arrange
            var repository = new UserRepository(_unitOfWork);
            var user = new User { UserId = 900, Activated = false, Email = "newuser2@weblog.com", FirstName = "New", LastName = "User", Password = "newuser" };
            repository.Add(user);
            var controller = new AccountController(_unitOfWork, _emailService);
            var model = new LogOnModel() { Email = "newuser2@weblog.com", Password = "newuser", RememberMe = true };

            //Act
            var result = controller.SignIn(model) as ViewResult;

            //Assert
            Assert.IsFalse(System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated);
            Assert.IsInstanceOf(typeof(LogOnModel), result.ViewData.Model);
        }

        [Test]
        public void SignIn_Action_Should_Redirect_To_Admin_Index_When_User_Is_Admins()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            var model = new LogOnModel() { Email = "admin@weblog.com", Password = "admin", RememberMe = true };

            //Act           
            var result = controller.SignIn(model) as RedirectToRouteResult;

            //Assert
            Assert.AreEqual("Admin", result.RouteValues["controller"]);
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }

        [Test]
        public void SignIn_Action_Should_Redirect_To_Specified_Url()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            var model = new LogOnModel() { Email = "guest@weblog.com", Password = "guest", RememberMe = true };

            //Act
            var result = controller.SignIn(model, "/Account/MyAccount") as RedirectResult;

            //Assert
            Assert.AreEqual("/Account/MyAccount", result.Url);
        }

        [Test]
        public void SignOut_Action_Should_Succeed()
        {
            //Arrange
            var controller = new AccountController(_unitOfWork, _emailService);
            controller.CurrentUser = _guest;
            controller.SetFakeControllerContext(_guestPrincipal, _guest);
  
            //Act
            var result = controller.SignOut() as RedirectToRouteResult;

            //Assert
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Post", result.RouteValues["controller"]);
        }

    }
}